package com.mybatisplugin.springboot.conf.ehcache;

import org.apache.shiro.cache.ehcache.EhCacheManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

@Configuration
public class EhCacheConfiguration {
	
	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(EhCacheConfiguration.class);

	@Bean("ehCacheShiroManager")
    public EhCacheManager ehCacheManager(@Qualifier("ehCacheManagerFactoryBean")EhCacheManagerFactoryBean ehCacheManagerFactoryBean){
    	EhCacheManager cacheManager=new EhCacheManager();
    	cacheManager.setCacheManager(ehCacheManagerFactoryBean.getObject());
        return cacheManager;
    }
	
	@Bean(name="ehCacheManagerFactoryBean")
    public EhCacheManagerFactoryBean ehCacheManagerFactoryBean(){
    	EhCacheManagerFactoryBean ehCacheManagerFactoryBean=new EhCacheManagerFactoryBean();
    	ehCacheManagerFactoryBean.setConfigLocation(new ClassPathResource("ehcache-shiro.xml"));
    	ehCacheManagerFactoryBean.setShared(true);
        return ehCacheManagerFactoryBean;
    }

}